<?php

namespace app\service;

use app\manager\RedisInstance;
use app\model\RegisterModel;
use think\Exception;
use think\facade\Cache;
use think\facade\Session;
use think\facade\View;

class LoginService
{
    public function login($phone,$pwd){
        //echo '123';exit();
//        $phone = $req['phone'];
//        $pwd = $req['pwd'];
        $user = RegisterModel::seletByPhone($phone);
        if (empty($user)){
            throw new \Think\Exception('手机号错误');
        }
        $newPwd = \md5($pwd);
        if ($user['pwd']!=$newPwd){
            throw new Exception('密码错误');
        }
        //$token = Md5::md5($user['id']);å
        $token = \md5('login:'.$phone);
        //echo $token;exit();
       // RedisInstance::set($token,$user['id']);
        //Cache::store('redis')->set($token,$user['id']);
       // Session::set($phone,$token);
        //$se = Session::get($phone);
        //echo $token;exit();
        $_SESSION['uid']=$user['id'];
        cookie('token',$token,3600);
//        setcookie()
//        response()->cookie()
        return $token;
    }

}